#编辑页测试
from selenium.webdriver.common.by import By
from common.Utils import BlogDriver
from test.BlogLoginTest import login




class BlogEdit:
    driver=""
    url=""
    def __init__(self):
        self.url="http://8.137.19.140:9090/blog_edit.html"
        self.driver=BlogDriver.driver
        self.driver.get(self.url)

    #博客详情页导航条检查
    def check_ele(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(4)")
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(5)")
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(6)")

    #正确发布博客(登陆情况下)
    def Suc_Edit(self):
        #发布文章按钮
        self.driver.find_element(By.CSS_SELECTOR,"#submit")
        #标题输入框
        self.driver.find_element(By.CSS_SELECTOR,"#title").send_keys ("自动化测试")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        actual = self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1537) > div.title").text
        assert actual == "自动化测试"

    #异常发布博客(登陆状态下)
    def Fail_Edit(self):
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()

        BlogDriver.getScreenShot()
        #出现弹窗
        alert=self.driver.switch_to.alert
        alert.accept()

    #异常发布博客(不登录状态下)
    def Fail_Edit_notLogin(self):
        self.url="http://8.137.19.140:9090/blog_edit.html"
        self.driver.get(self.url)

        #检查博客编辑页导航条元素
        self.check_ele()

        #登陆后会显示博客的编辑页，但是提交后会返回登陆页面
        self.driver.find_element(By.CSS_SELECTOR,"#title").send_keys("博客")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        #未登陆情况下会返回主页，查看主页的提交那妞
        self.driver.find_element(By.CSS_SELECTOR,"#submit")

        #检查返回主页后，导航条是否正常显示
        login.Check_ele_Login()
Edit=BlogEdit()


